//SPDX-FileCopyrightText: Copyright 2022-2024 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package admin_common

import (
	"context"

	"atomgit.com/openlinksaas-org/api-server/config"
	"atomgit.com/openlinksaas-org/api-server/dao"
	"atomgit.com/openlinksaas-org/proto-gen-go.git/admin_auth_api"
)

func GetAdminUserConfig(ctx context.Context, adminCfg *config.AdminCfg, adminUserName string) (*admin_auth_api.AdminUserInfo, error) {
	if adminUserName == adminCfg.SuperUser {
		return &admin_auth_api.AdminUserInfo{
			UserName: adminCfg.SuperUser,
			UserDesc: "",
			PubKey:   adminCfg.SuperPubKey,
			PermInfo: &admin_auth_api.AdminPermInfo{
				UserPerm: &admin_auth_api.UserPerm{
					Read:           true,
					Create:         true,
					SetState:       true,
					ResetPassword:  true,
					SetTestAccount: true,
				},
				ProjectPerm: &admin_auth_api.ProjectPerm{
					Read:        true,
					Update:      true,
					AccessEvent: true,
				},
				ProjectMemberPerm: &admin_auth_api.ProjectMemberPerm{
					Read: true,
				},
				MenuPerm: &admin_auth_api.MenuPerm{
					Read:   true,
					Add:    true,
					Remove: true,
					Update: true,
				},
				AppStorePerm: &admin_auth_api.AppStorePerm{
					Read:       true,
					AddCate:    true,
					UpdateCate: true,
					RemoveCate: true,
					AddApp:     true,
					UpdateApp:  true,
					RemoveApp:  true,
				},
				IdeaStorePerm: &admin_auth_api.IdeaStorePerm{
					Read:            true,
					CreateStoreCate: true,
					UpdateStoreCate: true,
					RemoveStoreCate: true,
					CreateStore:     true,
					UpdateStore:     true,
					MoveStore:       true,
					RemoveStore:     true,
					CreateIdea:      true,
					UpdateIdea:      true,
					MoveIdea:        true,
					RemoveIdea:      true,
				},
				WidgetStorePerm: &admin_auth_api.WidgetStorePerm{
					Read:         true,
					AddWidget:    true,
					UpdateWidget: true,
					RemoveWidget: true,
				},
				SwStorePerm: &admin_auth_api.SwStorePerm{
					Read:           true,
					AddCate:        true,
					UpdateCate:     true,
					RemoveCate:     true,
					AddSoftWare:    true,
					UpdateSoftWare: true,
					RemoveSoftWare: true,
				},
				OrgPerm: &admin_auth_api.OrgPerm{
					Read:   true,
					Update: true,
				},
				OrgMemberPerm: &admin_auth_api.OrgMemberPerm{
					Read: true,
				},
				KeywordPerm: &admin_auth_api.KeywordPerm{
					Read:   true,
					Add:    true,
					Remove: true,
				},
				FeedBackPerm: &admin_auth_api.FeedBackPerm{
					Read:   true,
					Remove: true,
				},
				RoadmapPerm: &admin_auth_api.RoadmapPerm{
					Read:            true,
					Create:          true,
					UpdateContent:   true,
					UpdateTag:       true,
					UpdatePubState:  true,
					Remove:          true,
					ChangeOwner:     true,
					AddWhiteUser:    true,
					UpdateWhiteUser: true,
					RemoveWhiteUser: true,
					AddTag:          true,
					ModifyTag:       true,
					RemoveTag:       true,
				},
				SuperAdminUser: true,
			},
		}, nil
	}
	userItem, err := dao.AdminUserDao.Get(ctx, adminUserName)
	if err != nil {
		return nil, err
	}
	return userItem.ToAdminUserInfo()
}
